<?php
/**
 * Tên file mình có thể tự chọn nhưng nên đặc theo têm controller sẽ dễ quản lý
 */

/**
 * Tên class: Example_Models_Dao_Pdo_Mysql_Example(Tenmodule_Models_Dao_Pdo_Mysql_Tenfile)
 */

class Enterprise_Models_Dao_Pdo_Mysql_Info extends Tomato_Model_Dao
    implements Enterprise_Models_Interface_Info
{
    public function convert($entity)
    {
        return new Enterprise_Models_Info($entity);
    }

    public function add($info){
        $this->_conn->insert($this->_prefix . 'enterprise_info',
                            array(
                                'enterprise_id' => $info->enterprise_id,
                                'info_title'    => $info->info_title,
                                'info_string'   => $info->info_string,
                                'info_number'   => $info->info_number,
                                'language'      => $info->language,
                            ));
        return $this->_conn->lastInsertId($this->_prefix . 'enterprise_info');
    }

    public function getById($id){
        $rs = $this->_conn
                    ->select()
                    ->from(array('i' => $this->_prefix . 'enterprise_info'))
                    ->where('i.enterprise_id = ?', $id)
                    ->where('i.language = ?', $this->_lang)
                    ->query()
                    ->fetchAll();
        return new Tomato_Model_RecordSet($rs, $this);
    }

    public function update($info)
    {
        return $this->_conn->update($this->_prefix . 'enterprise_info',
                                array(
                                    'info_title'    => $info->info_title,
                                    'info_string'   => $info->info_string,
                                    'info_number'   => $info->info_number,
                                ),
                                array(
                                    'enterprise_id = ?' => $info->enterprise_id,
                                ));
    }
    public function delete($id){
        /*$this->_conn->delete($this->_prefix . 'enterprise_info',
                            array(
                                'enterprise_id = ?' => $id,
                                'language = ?' => $this->_lang,
                            ));*/
        $sql = "Delete from enterprise_info where `enterprise_id` = {$id} AND `language` = '{$this->_lang}'";
        $this->_conn->query($sql);
    }
}
